package com.cskaoyan.controller.lzp_controller;

import com.cskaoyan.bean.AdminListRespVo;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.lzp.*;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * \* Description:商场管理的订单管理
 * \* @author: Lizhanpeng
 * \* Date: 2022/5/6
 * \
 */
@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @GetMapping("channel")
    public AdminListRespVo channel() {
        List<OrderChannel> orderChannels = orderService.queryChannel();
        return AdminListRespVo.listOk(orderChannels);
    }


    @GetMapping("detail")
    public AdminListRespVo detail(String id) {
        OrderDetailVO orderDetail = orderService.queryDetail(id);
        return AdminListRespVo.listOk(orderDetail);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Map<String, Integer> map) {
        Integer orderId = map.get("orderId");
        int i = orderService.deleteByOrderId(orderId);
        return BaseRespVo.ok(null);
    }

    @GetMapping("list")
    public BaseRespVo list(BaseParam param, OrderListBO orderListBO) {
        OrderListData orderListData = orderService.list(param, orderListBO);
        return BaseRespVo.listOk(orderListData);
    }

    @PostMapping("refund")
    public BaseRespVo refund(@RequestBody OrderRefundBO orderRefundBO) {
        Integer refund = orderService.refund(orderRefundBO);
        if (refund == 1) {
            return BaseRespVo.listOk(null);
        }
        return BaseRespVo.invalidData("失败");
    }

    @PostMapping("ship")
    public BaseRespVo ship(@RequestBody OrderShipBO orderShipBO) {
        Integer ship = orderService.ship(orderShipBO);
        if (ship>0){
            return BaseRespVo.listOk(null);
        }
        return BaseRespVo.invalidData("fail");
    }


}
